
/**
 * Bullet
 * -- Part of the Flixel Power Tools set
 * 
 * v1.2 Removed "id" and used the FlxSprite ID value instead
 * v1.1 Updated to support fire callbacks, sounds, random variances and lifespan
 * v1.0 First release
 * 
 * @version 1.2 - October 10th 2011
 * @link http://www.photonstorm.com
 * @author Richard Davey / Photon Storm
 */

package tools
{	
	import entities.Entity;
	
	import flash.display.BitmapData;
	import flash.geom.Matrix;
	import flash.utils.getTimer;
	
	import org.flixel.FlxObject;
	import org.flixel.FlxPoint;
	import org.flixel.FlxSprite;
	import org.flixel.plugin.photonstorm.BaseTypes.Bullet;
	import org.flixel.plugin.photonstorm.FlxMath;
	import org.flixel.plugin.photonstorm.FlxVelocity;
	import org.flixel.plugin.photonstorm.FlxWeapon;
	
	import tools.MyFlxSprite;
	

	
	public class MyBullet extends Bullet
	{
		
		public var parent:Entity;
		public var power:uint = 1;
		
		
		public function MyBullet(weapon:FlxWeapon, id:uint, Parent:Entity, Power:uint = 1) {
			super(weapon, id);
			power = Power;
			parent = Parent;
		}
		
		public function loadGraphicWithBitmap(bitmap:BitmapData, Animated:Boolean=false, Reverse:Boolean=false, Width:uint=0, Height:uint=0, Unique:Boolean=false):FlxSprite {
			_bakedRotation = 0;
			_pixels = bitmap;
			
			if (Reverse) {
				var newPixels:BitmapData = new BitmapData(pixels.width << 1, pixels.height, true, 0x00000000);
				newPixels.draw(pixels);
				var mtx:Matrix = new Matrix();
				mtx.scale(-1, 1);
				mtx.translate(newPixels.width, 0);
				newPixels.draw(pixels, mtx);
				pixels = newPixels;
				_flipped = _pixels.width >> 1;
			} else
				_flipped = 0;
			
			if (Width == 0) {
				if (Animated)
					Width = _pixels.height;
				else if (_flipped > 0)
					Width = _pixels.width * 0.5;
				else
					Width = _pixels.width;
			}
			
			width = frameWidth = Width;
			
			if (Height == 0) {
				if (Animated)
					Height = width;
				else
					Height = _pixels.height;
			}
			height = frameHeight = Height;
			resetHelpers();
			return this;
		}
	}
}
